home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / emacs.lha / emacs-19.16 / info / emacs-9 (.txt) < prev    next >
GNU Info File  |  1993-07-06  |  46KB  |  820 lines

  1. This is Info file ../info/emacs, produced by Makeinfo-1.54 from the
  2. input file emacs.texi.
  3. File: emacs,  Node: Outline Visibility,  Prev: Outline Motion,  Up: Outline Mode
  4. Outline Visibility Commands
  5. ---------------------------
  6.    The other special commands of outline mode are used to make lines
  7. visible or invisible.  Their names all start with `hide' or `show'.
  8. Most of them fall into pairs of opposites.  They are not undoable;
  9. instead, you can undo right past them.  Making lines visible or
  10. invisible is simply not recorded by the undo mechanism.
  11. `M-x hide-body'
  12.      Make all body lines in the buffer invisible.
  13. `M-x show-all'
  14.      Make all lines in the buffer visible.
  15. `C-c C-h'
  16.      Make everything under this heading invisible, not including this
  17.      heading itself
  18.      (`hide-subtree').
  19. `C-c C-s'
  20.      Make everything under this heading visible, including body,
  21.      subheadings, and their bodies (`show-subtree').
  22. `M-x hide-leaves'
  23.      Make the body of this heading line, and of all its subheadings,
  24.      invisible.
  25. `M-x show-branches'
  26.      Make all subheadings of this heading line, at all levels, visible.
  27. `C-c C-i'
  28.      Make immediate subheadings (one level down) of this heading line
  29.      visible (`show-children').
  30. `M-x hide-entry'
  31.      Make this heading line's body invisible.
  32. `M-x show-entry'
  33.      Make this heading line's body visible.
  34.    Two commands that are exact opposites are `M-x hide-entry' and `M-x
  35. show-entry'.  They are used with point on a heading line, and apply
  36. only to the body lines of that heading.  The subtopics and their bodies
  37. are not affected.
  38.    Two more powerful opposites are `C-c C-h' (`hide-subtree') and `C-c
  39. C-s' (`show-subtree').  Both expect to be used when point is on a
  40. heading line, and both apply to all the lines of that heading's
  41. "subtree": its body, all its subheadings, both direct and indirect, and
  42. all of their bodies.  In other words, the subtree contains everything
  43. following this heading line, up to and not including the next heading of
  44. the same or higher rank.
  45.    Intermediate between a visible subtree and an invisible one is having
  46. all the subheadings visible but none of the body.  There are two
  47. commands for doing this, depending on whether you want to hide the
  48. bodies or make the subheadings visible.  They are `M-x hide-leaves' and
  49. `M-x show-branches'.
  50.    A little weaker than `show-branches' is `C-c C-i' (`show-children').
  51. It makes just the direct subheadings visible--those one level down.
  52. Deeper subheadings remain invisible, if they were invisible.
  53.    Two commands have a blanket effect on the whole file.  `M-x
  54. hide-body' makes all body lines invisible, so that you see just the
  55. outline structure.  `M-x show-all' makes all lines visible.  These
  56. commands can be thought of as a pair of opposites even though `M-x
  57. show-all' applies to more than just body lines.
  58.    You can turn off the use of ellipses at the ends of visible lines by
  59. setting `selective-display-ellipses' to `nil'.  Then there is no
  60. visible indication of the presence of invisible lines.
  61. File: emacs,  Node: TeX Mode,  Next: Nroff Mode,  Prev: Outline Mode,  Up: Text
  62. TeX Mode
  63. ========
  64.    TeX is a powerful text formatter written by Donald Knuth; it is also
  65. free, like GNU Emacs.  LaTeX is a simplified input format for TeX,
  66. implemented by TeX macros; it comes with TeX.  SliTeX is a special form
  67. of LaTeX.
  68.    Emacs has a special TeX mode for editing TeX input files.  It
  69. provides facilities for checking the balance of delimiters and for
  70. invoking TeX on all or part of the file.
  71.    TeX mode has three variants, Plain TeX mode, LaTeX mode, and SliTeX
  72. mode (these three distinct major modes differ only slightly).  They are
  73. designed for editing the three different formats.  The command `M-x
  74. tex-mode' looks at the contents of the buffer to determine whether the
  75. contents appear to be either LaTeX input or SliTeX input; it then
  76. selects the appropriate mode.  If it can't tell which is right (e.g.,
  77. the buffer is empty), the variable `tex-default-mode' controls which
  78. mode is used.
  79.    When `M-x tex-mode' does not guess right, you can use the commands
  80. `M-x plain-tex-mode', `M-x latex-mode', and `M-x slitex-mode' to select
  81. explicitly the particular variants of TeX mode.
  82. * Menu:
  83. * Editing: TeX Editing.   Special commands for editing in TeX mode.
  84. * LaTeX: LaTeX Editing.   Additional commands for LaTeX input files.
  85. * Printing: TeX Print.    Commands for printing part of a file with TeX.
  86. * Getting: TeX Distrib.   Getting the latest Unix TeX distribution.
  87. File: emacs,  Node: TeX Editing,  Next: LaTeX Editing,  Up: TeX Mode
  88. TeX Editing Commands
  89. --------------------
  90.    Here are the special commands provided in TeX mode for editing the
  91. text of the file.
  92.      Insert, according to context, either ```' or `"' or `'''
  93.      (`tex-insert-quote').
  94. `LFD'
  95.      Insert a paragraph break (two newlines) and check the previous
  96.      paragraph for unbalanced braces or dollar signs
  97.      (`tex-terminate-paragraph').
  98. `M-x validate-tex-region'
  99.      Check each paragraph in the region for unbalanced braces or dollar
  100.      signs.
  101. `C-c {'
  102.      Insert `{}' and position point between them (`tex-insert-braces').
  103. `C-c }'
  104.      Move forward past the next unmatched close brace (`up-list').
  105.    In TeX, the character `"' is not normally used; we use ```' to start
  106. a quotation and `''' to end one.  To make editing easier under this
  107. formatting convention, TeX mode overrides the normal meaning of the key
  108. `"' with a command that inserts a pair of single-quotes or backquotes
  109. (`tex-insert-quote').  To be precise, this command inserts ```' after
  110. whitespace or an open brace, `"' after a backslash, and `''' after any
  111. other character.
  112.    If you need the character `"' itself in unusual contexts, use `C-q'
  113. to insert it.  Also, `"' with a numeric argument always inserts that
  114. number of `"' characters.
  115.    In TeX mode, `$' has a special syntax code which attempts to
  116. understand the way TeX math mode delimiters match.  When you insert a
  117. `$' that is meant to exit math mode, the position of the matching `$'
  118. that entered math mode is displayed for a second.  This is the same
  119. feature that displays the open brace that matches a close brace that is
  120. inserted.  However, there is no way to tell whether a `$' enters math
  121. mode or leaves it; so when you insert a `$' that enters math mode, the
  122. previous `$' position is shown as if it were a match, even though they
  123. are actually unrelated.
  124.    TeX uses braces as delimiters that must match.  Some users prefer to
  125. keep braces balanced at all times, rather than inserting them singly.
  126. Use `C-c {' (`tex-insert-braces') to insert a pair of braces.  It
  127. leaves point between the two braces so you can insert the text that
  128. belongs inside.  Afterward, use the command `C-c }' (`up-list') to move
  129. forward past the close brace.
  130.    There are two commands for checking the matching of braces.  LFD
  131. (`tex-terminate-paragraph') checks the paragraph before point, and
  132. inserts two newlines to start a new paragraph.  It prints a message in
  133. the echo area if any mismatch is found.  `M-x validate-tex-region'
  134. checks a region, paragraph by paragraph.  When it finds a paragraph that
  135. contains a mismatch, it displays point at the beginning of the paragraph
  136. for a few seconds and pushes a mark at that spot.  Scanning continues
  137. until the whole buffer has been checked or until you type another key.
  138. The positions of the last several paragraphs with mismatches can be
  139. found in the mark ring (*note Mark Ring::.).
  140.    Note that Emacs commands count square brackets and parentheses in
  141. TeX mode, not just braces.  This is not strictly correct for the
  142. purpose of checking TeX syntax.  However, parentheses and square
  143. brackets are likely to be used in text as matching delimiters and it is
  144. useful for the various motion commands and automatic match display to
  145. work with them.
  146. File: emacs,  Node: LaTeX Editing,  Next: TeX Print,  Prev: TeX Editing,  Up: TeX Mode
  147. LaTeX Editing Commands
  148. ----------------------
  149.    LaTeX mode provides a few extra features not applicable to plain TeX.
  150. `C-c C-o'
  151.      Insert `\begin' and `\end' for LaTeX block and position point on a
  152.      line between them. (`tex-latex-block').
  153. `C-c C-e'
  154.      Close the last unended block for LaTeX (`tex-close-latex-block').
  155.    In LaTeX input, `\begin' and `\end' commands are used to group
  156. blocks of text.  To insert a `\begin' and a matching `\end' (on a new
  157. line following the `\begin'), use `C-c C-o' (`tex-latex-block').  A
  158. blank line is inserted between the two, and point is left there.
  159.    Emacs knows all of the standard LaTeX block names and will
  160. permissively complete a partially entered block name (*note
  161. Completion::.).  You can add your own list of block names to those
  162. known by Emacs with the variable `latex-block-names'.  For example, to
  163. add `theorem', `corollary', and `proof', include the line
  164.      (setq latex-block-names '("theorem" "corollary" "proof"))
  165. to your `.emacs' file.
  166.    In LaTeX input, `\begin' and `\end' commands must balance.  You can
  167. use `C-c C-e' (`tex-close-latex-block') to insert automatically a
  168. matching `\end' to match the last unmatched `\begin'.  The `\end' will
  169. be indented to match the corresponding `\begin'.  The `\end' will be
  170. followed by a newline if point is at the beginning of a line.
  171. File: emacs,  Node: TeX Print,  Next: TeX Distrib,  Prev: LaTeX Editing,  Up: TeX Mode
  172. TeX Printing Commands
  173. ---------------------
  174.    You can invoke TeX as an inferior of Emacs on either the entire
  175. contents of the buffer or just a region at a time.  Running TeX in this
  176. way on just one chapter is a good way to see what your changes look
  177. like without taking the time to format the entire file.
  178. `C-c C-r'
  179.      Invoke TeX on the current region, together with the buffer's header
  180.      (`tex-region').
  181. `C-c C-b'
  182.      Invoke TeX on the entire current buffer (`tex-buffer').
  183. `C-c TAB'
  184.      Invoke BibTeX on the current file (`tex-bibtex-file').
  185. `C-c C-f'
  186.      Invoke TeX on the current file (`tex-file').
  187. `C-c C-l'
  188.      Recenter the window showing output from the inferior TeX so that
  189.      the last line can be seen (`tex-recenter-output-buffer').
  190. `C-c C-k'
  191.      Kill the TeX subprocess (`tex-kill-job').
  192. `C-c C-p'
  193.      Print the output from the last `C-c C-r', `C-c C-b', or `C-c C-f'
  194.      command (`tex-print').
  195. `C-c C-v'
  196.      Preview the output from the last `C-c C-r', `C-c C-b', or `C-c
  197.      C-f' command (`tex-view').
  198. `C-c C-q'
  199.      Show the printer queue (`tex-show-print-queue').
  200.    You can pass the current buffer through an inferior TeX by means of
  201. `C-c C-b' (`tex-buffer').  The formatted output appears in a temporary;
  202. to print it, type `C-c C-p' (`tex-print').  Afterward use `C-c C-q'
  203. (`tex-show-print-queue') to view the progress of your output towards
  204. being printed. If your terminal has the ability to display TeX output
  205. files, you can preview the output on the terminal with `C-c C-v'
  206. (`tex-view').
  207.    You can specify the directory to use for running TeX by setting the
  208. variable `tex-directory'.  `"."' is the default value.  If your
  209. environment variable `TEXINPUTS' contains relative directory names, or
  210. if your files contains `\input' commands with relative file names, then
  211. `tex-directory' *must* be `"."' or you will get the wrong results.
  212. Otherwise, it is safe to specify some other directory, such as `/tmp'.
  213.    If you want to specify which shell commands are used in the inferior
  214. TeX, you can do so by setting the values of the variables
  215. `tex-run-command', `latex-run-command', `slitex-run-command',
  216. `tex-dvi-print-command', `tex-dvi-view-command', and
  217. `tex-show-queue-command'.  You *must* set the value of
  218. `tex-dvi-view-command' for your particular terminal; this variable has
  219. no default value.  The other variables have default values that may (or
  220. may not) be appropriate for your system.
  221.    Normally, the file name given to these commands comes at the end of
  222. the command string; for example, `latex FILENAME'.  In some cases,
  223. however, the file name needs to be embedded in the command; an example
  224. is when you need to provide the file name as an argument to one command
  225. whose output is piped to another.  You can specify where to put the
  226. file name with `*' in the command string.  For example,
  227.      (setq tex-dvi-print-command "dvips -f * | lpr")
  228.    The terminal output from TeX, including any error messages, appears
  229. in a buffer called `*tex-shell*'.  If TeX gets an error, you can switch
  230. to this buffer and feed it input (this works as in Shell mode; *note
  231. Interactive Shell::.).  Without switching to this buffer you can scroll
  232. it so that its last line is visible by typing `C-c C-l'.
  233.    Type `C-c C-k' (`tex-kill-job') to kill the TeX process if you see
  234. that its output is no longer useful.  Using `C-c C-b' or `C-c C-r' also
  235. kills any TeX process still running.
  236.    You can also pass an arbitrary region through an inferior TeX by
  237. typing `C-c C-r' (`tex-region').  This is tricky, however, because most
  238. files of TeX input contain commands at the beginning to set parameters
  239. and define macros, without which no later part of the file will format
  240. correctly.  To solve this problem, `C-c C-r' allows you to designate a
  241. part of the file as containing essential commands; it is included before
  242. the specified region as part of the input to TeX.  The designated part
  243. of the file is called the "header".
  244.    To indicate the bounds of the header in Plain TeX mode, you insert
  245. two special strings in the file.  Insert `%**start of header' before the
  246. header, and `%**end of header' after it.  Each string must appear
  247. entirely on one line, but there may be other text on the line before or
  248. after.  The lines containing the two strings are included in the header.
  249. If `%**start of header' does not appear within the first 100 lines of
  250. the buffer, `C-c C-r' assumes that there is no header.
  251.    In LaTeX mode, the header begins with `\documentstyle' and ends with
  252. `\begin{document}'.  These are commands that LaTeX requires you to use
  253. in any case, so nothing special needs to be done to identify the header.
  254.    The commands (`tex-buffer') and (`tex-region') do all of their work
  255. in a temporary directory, and do not have available any of the auxiliary
  256. files needed by TeX for cross-references; these commands are generally
  257. not suitable for running the final copy in which all of the
  258. cross-references need to be correct.  When you want the auxiliary
  259. files, use `C-c C-f' (`tex-file') which runs TeX on the current
  260. buffer's file, in that file's directory.  Before TeX runs, you will be
  261. asked about saving any modified buffers.  Generally, you need to use
  262. (`tex-file') twice to get cross-references correct.
  263.    For LaTeX files, you can use BibTeX to process the auxiliary file
  264. for the current buffer's file.  BibTeX looks up bibliographic citations
  265. in a data base and prepares the cited references for the bibliography
  266. section.  The command `C-c TAB' (`tex-bibtex-file') runs the shell
  267. command (`tex-bibtex-command') to produce a `.bbl' file for the current
  268. buffer's file.  Generally, you need to do `C-c C-f' (`tex-file') once
  269. to generate the `.aux' file, then do `C-c TAB' (`tex-bibtex-file'), and
  270. then repeat `C-c C-f' (`tex-file') twice more to get the
  271. cross-references correct.
  272.    Entering any kind of TeX mode runs the hooks `text-mode-hook' and
  273. `tex-mode-hook'.  Then it runs either `plain-tex-mode-hook' or
  274. `latex-mode-hook', whichever is appropriate.  For SliTeX files, it
  275. calls `slitex-mode-hook'.  Starting the TeX shell runs the hook
  276. `tex-shell-hook'.  *Note Hooks::.
  277. File: emacs,  Node: TeX Distrib,  Prev: TeX Print,  Up: TeX Mode
  278. Unix TeX Distribution
  279. ---------------------
  280.    TeX for Unix systems can be obtained from the University of
  281. Washington for a distribution fee.
  282.    To order a full distribution, send $200.00 for a 1/2-inch 9-track
  283. 1600 bpi (tar or cpio) tape reel, or $210.00 for a 1/4-inch 4-track
  284. QIC-24 (tar or cpio) cartridge, payable to the University of Washington
  285.      Northwest Computing Support Center
  286.      DR-10, Thomson Hall 35
  287.      University of Washington
  288.      Seattle, Washington 98195
  289. Purchase orders are acceptable, but there is an extra charge of $10.00,
  290. to pay for processing charges.
  291. For overseas orders please add $20.00 to the base cost for shipment via
  292. air parcel post, or $30.00 for shipment via courier.
  293.    The normal distribution is a tar tape, blocked 20, 1600 bpi, on an
  294. industry standard 2400 foot half-inch reel.  The physical format for
  295. the 1/4 inch streamer cartridges uses QIC-11, 8000 bpi, 4-track
  296. serpentine recording for the SUN.  Also, System V tapes can be written
  297. in cpio format, blocked 5120 bytes, ASCII headers.
  298. File: emacs,  Node: Nroff Mode,  Prev: TeX Mode,  Up: Text
  299. Nroff Mode
  300. ==========
  301.    Nroff mode is a mode like Text mode but modified to handle nroff
  302. commands present in the text.  Invoke `M-x nroff-mode' to enter this
  303. mode.  It differs from Text mode in only a few ways.  All nroff command
  304. lines are considered paragraph separators, so that filling will never
  305. garble the nroff commands.  Pages are separated by `.bp' commands.
  306. Comments start with backslash-doublequote.  Also, three special
  307. commands are provided that are not in Text mode:
  308. `M-n'
  309.      Move to the beginning of the next line that isn't an nroff command
  310.      (`forward-text-line').  An argument is a repeat count.
  311. `M-p'
  312.      Like `M-n' but move up (`backward-text-line').
  313. `M-?'
  314.      Prints in the echo area the number of text lines (lines that are
  315.      not nroff commands) in the region (`count-text-lines').
  316.    The other feature of Nroff mode is that you can turn on Electric
  317. Nroff mode.  This is a minor mode that you can turn on or off with `M-x
  318. electric-nroff-mode' (*note Minor Modes::.).  When the mode is on, each
  319. time you use RET to end a line that contains an nroff command that
  320. opens a kind of grouping, the matching nroff command to close that
  321. grouping is automatically inserted on the following line.  For example,
  322. if you are at the beginning of a line and type `. ( b RET', this
  323. inserts the matching command `.)b' on a new line following point.
  324.    Entering Nroff mode runs the hook `text-mode-hook', followed by the
  325. hook `nroff-mode-hook' (*note Hooks::.).
  326. File: emacs,  Node: Programs,  Next: Building,  Prev: Text,  Up: Top
  327. Editing Programs
  328. ****************
  329.    Emacs has many commands designed to understand the syntax of
  330. programming languages such as Lisp and C.  These commands can
  331.    * Move over or kill balanced expressions or "sexps" (*note Lists::.).
  332.    * Move over or mark top-level expressions--"defuns", in Lisp;
  333.      functions, in C (*note Defuns::.).
  334.    * Show how parentheses balance (*note Matching::.).
  335.    * Insert, kill or align comments (*note Comments::.).
  336.    * Follow the usual indentation conventions of the language (*note
  337.      Program Indent::.).
  338.    The commands for words, sentences and paragraphs are very useful in
  339. editing code even though their canonical application is for editing
  340. human language text.  Most symbols contain words (*note Words::.);
  341. sentences can be found in strings and comments (*note Sentences::.).
  342. Paragraphs per se don't exist in code, but the paragraph commands are
  343. useful anyway, because programming language major modes define
  344. paragraphs to begin and end at blank lines (*note Paragraphs::.).
  345. Judicious use of blank lines to make the program clearer will also
  346. provide interesting chunks of text for the paragraph commands to work
  347.    The selective display feature is useful for looking at the overall
  348. structure of a function (*note Selective Display::.).  This feature
  349. causes only the lines that are indented less than a specified amount to
  350. appear on the screen.
  351. * Menu:
  352. * Program Modes::     Major modes for editing programs.
  353. * Lists::             Expressions with balanced parentheses.
  354. * List Commands::     The commands for working with list and sexps.
  355. * Defuns::            Each program is made up of separate functions.
  356.                         There are editing commands to operate on them.
  357. * Program Indent::    Adjusting indentation to show the nesting.
  358. * Matching::          Insertion of a close-delimiter flashes matching open.
  359. * Comments::          Inserting, killing, and aligning comments.
  360. * Balanced Editing::  Inserting two matching parentheses at once, etc.
  361. * Symbol Completion:: Completion on symbol names of your program or language.
  362. * Documentation::     Getting documentation of functions you plan to call.
  363. * Change Log::        Maintaining a change history for your program.
  364. * Tags::              Go direct to any function in your program in one
  365.                         command.  Tags remembers which file it is in.
  366. * Emerge::          A convenient way of merging two versions of a program.
  367. * C Mode::          Special commands of C mode (and C++ mode).
  368. * Fortran::          Fortran mode and its special features.
  369. * Asm Mode::          Asm mode and its special features.
  370. File: emacs,  Node: Program Modes,  Next: Lists,  Up: Programs
  371. Major Modes for Programming Languages
  372. =====================================
  373.    Emacs also has major modes for the programming languages Lisp, Scheme
  374. (a variant of Lisp), Awk, C, C++, Perl, Icon, Fortran and Muddle
  375. (another variant of Lisp).  There is also a major mode for makefiles,
  376. called Makefile mode.
  377.    Ideally, a major mode should be implemented for each programming
  378. language that you might want to edit with Emacs; but often the mode for
  379. one language can serve for other syntactically similar languages.  The
  380. language modes that exist are those that someone decided to take the
  381. trouble to write.
  382.    There are several forms of Lisp mode, which differ in the way they
  383. interface to Lisp execution.  *Note Executing Lisp::.
  384.    Each of the programming language modes defines the TAB key to run an
  385. indentation function that knows the indentation conventions of that
  386. language and updates the current line's indentation accordingly.  For
  387. example, in C mode TAB is bound to `c-indent-line'.  LFD is normally
  388. defined to do RET followed by TAB; thus, it too indents in a
  389. mode-specific fashion.
  390.    In most programming languages, indentation is likely to vary from
  391. line to line.  So the major modes for those languages rebind DEL to
  392. treat a tab as if it were the equivalent number of spaces (using the
  393. command `backward-delete-char-untabify').  This makes it possible to
  394. rub out indentation one column at a time without worrying whether it is
  395. made up of spaces or tabs.  Use `C-b C-d' to delete a tab character
  396. before point, in these modes.
  397.    Programming language modes define paragraphs to be separated only by
  398. blank lines, so that the paragraph commands remain useful.  Auto Fill
  399. mode, if enabled in a programming language major mode, indents the new
  400. lines which it creates.
  401.    Turning on a major mode runs a normal hook called the "mode hook",
  402. which is the value of a Lisp variable.  For example, turning on C mode
  403. runs the hook `c-mode-hook'.  Mode hook variables for other programming
  404. language modes include `lisp-mode-hook', `emacs-lisp-mode-hook',
  405. `lisp-interaction-mode-hook', `scheme-mode-hook' and
  406. `muddle-mode-hook'.  *Note Hooks::.
  407. File: emacs,  Node: Lists,  Next: List Commands,  Prev: Program Modes,  Up: Programs
  408. Lists and Sexps
  409. ===============
  410.    By convention, Emacs keys for dealing with balanced expressions are
  411. usually Control-Meta characters.  They tend to be analogous in function
  412. to their Control and Meta equivalents.  These commands are usually
  413. thought of as pertaining to expressions in programming languages, but
  414. can be useful with any language in which some sort of parentheses exist
  415. (including human languages).
  416.    These commands fall into two classes.  Some deal only with "lists"
  417. (parenthetical groupings).  They see nothing except parentheses,
  418. brackets, braces (whichever ones must balance in the language you are
  419. working with), and escape characters that might be used to quote those.
  420.    The other commands deal with expressions or "sexps".  The word `sexp'
  421. is derived from "s-expression", the ancient term for an expression in
  422. Lisp.  But in Emacs, the notion of `sexp' is not limited to Lisp.  It
  423. refers to an expression in whatever language your program is written in.
  424. Each programming language has its own major mode, which customizes the
  425. syntax tables so that expressions in that language count as sexps.
  426.    Sexps typically include symbols, numbers, and string constants, as
  427. well as anything contained in parentheses, brackets or braces.
  428.    In languages that use prefix and infix operators, such as C, it is
  429. not possible for all expressions to be sexps.  For example, C mode does
  430. not recognize `foo + bar' as a sexp, even though it *is* a C expression;
  431. it recognizes `foo' as one sexp and `bar' as another, with the `+' as
  432. punctuation between them.  This is a fundamental ambiguity: both `foo +
  433. bar' and `foo' are legitimate choices for the sexp to move over if
  434. point is at the `f'.  Note that `(foo + bar)' is a single sexp in C
  435. mode.
  436.    Some languages have obscure forms of syntax for expressions that
  437. nobody has bothered to make Emacs understand properly.
  438. File: emacs,  Node: List Commands,  Next: Defuns,  Prev: Lists,  Up: Programs
  439. List And Sexp Commands
  440. ======================
  441. `C-M-f'
  442.      Move forward over a sexp (`forward-sexp').
  443. `C-M-b'
  444.      Move backward over a sexp (`backward-sexp').
  445. `C-M-k'
  446.      Kill sexp forward (`kill-sexp').
  447. `C-M-u'
  448.      Move up and backward in list structure (`backward-up-list').
  449. `C-M-d'
  450.      Move down and forward in list structure (`down-list').
  451. `C-M-n'
  452.      Move forward over a list (`forward-list').
  453. `C-M-p'
  454.      Move backward over a list (`backward-list').
  455. `C-M-t'
  456.      Transpose expressions (`transpose-sexps').
  457. `C-M-@'
  458.      Put mark after following expression (`mark-sexp').
  459.    To move forward over a sexp, use `C-M-f' (`forward-sexp').  If the
  460. first significant character after point is an opening delimiter (`(' in
  461. Lisp; `(', `[' or `{' in C), `C-M-f' moves past the matching closing
  462. delimiter.  If the character begins a symbol, string, or number,
  463. `C-M-f' moves over that.
  464.    The command `C-M-b' (`backward-sexp') moves backward over a sexp.
  465. The detailed rules are like those above for `C-M-f', but with
  466. directions reversed.  If there are any prefix characters (single-quote,
  467. backquote and comma, in Lisp) preceding the sexp, `C-M-b' moves back
  468. over them as well.  The sexp commands move across comments as if they
  469. were whitespace in most modes.
  470.    `C-M-f' or `C-M-b' with an argument repeats that operation the
  471. specified number of times; with a negative argument, it moves in the
  472. opposite direction.
  473.    Killing a sexp at a time can be done with `C-M-k' (`kill-sexp').
  474. `C-M-k' kills the characters that `C-M-f' would move over.
  475.    The "list commands" move over lists like the sexp commands but skip
  476. blithely over any number of other kinds of sexps (symbols, strings,
  477. etc).  They are `C-M-n' (`forward-list') and `C-M-p' (`backward-list').
  478. The main reason they are useful is that they usually ignore comments
  479. (since the comments usually do not contain any lists).
  480.    `C-M-n' and `C-M-p' stay at the same level in parentheses, when
  481. that's possible.  To move *up* one (or N) levels, use `C-M-u'
  482. (`backward-up-list').  `C-M-u' moves backward up past one unmatched
  483. opening delimiter.  A positive argument serves as a repeat count; a
  484. negative argument reverses direction of motion and also requests
  485. repetition, so it moves forward and up one or more levels.
  486.    To move *down* in list structure, use `C-M-d' (`down-list').  In
  487. Lisp mode, where `(' is the only opening delimiter, this is nearly the
  488. same as searching for a `('.  An argument specifies the number of levels
  489. of parentheses to go down.
  490.    A somewhat random-sounding command which is nevertheless handy is
  491. `C-M-t' (`transpose-sexps'), which drags the previous sexp across the
  492. next one.  An argument serves as a repeat count, and a negative
  493. argument drags backwards (thus canceling out the effect of `C-M-t' with
  494. a positive argument).  An argument of zero, rather than doing nothing,
  495. transposes the sexps ending after point and the mark.
  496.    To make the region be the next sexp in the buffer, use `C-M-@'
  497. (`mark-sexp') which sets mark at the same place that `C-M-f' would move
  498. to.  `C-M-@' takes arguments like `C-M-f'.  In particular, a negative
  499. argument is useful for putting the mark at the beginning of the
  500. previous sexp.
  501.    The list and sexp commands' understanding of syntax is completely
  502. controlled by the syntax table.  Any character can, for example, be
  503. declared to be an opening delimiter and act like an open parenthesis.
  504. *Note Syntax::.
  505. File: emacs,  Node: Defuns,  Next: Program Indent,  Prev: List Commands,  Up: Programs
  506. Defuns
  507. ======
  508.    In Emacs, a parenthetical grouping at the top level in the buffer is
  509. called a "defun".  The name derives from the fact that most top-level
  510. lists in a Lisp file are instances of the special form `defun', but any
  511. top-level parenthetical grouping counts as a defun in Emacs parlance
  512. regardless of what its contents are, and regardless of the programming
  513. language in use.  For example, in C, the body of a function definition
  514. is a defun.
  515. `C-M-a'
  516.      Move to beginning of current or preceding defun
  517.      (`beginning-of-defun').
  518. `C-M-e'
  519.      Move to end of current or following defun (`end-of-defun').
  520. `C-M-h'
  521.      Put region around whole current or following defun (`mark-defun').
  522.    The commands to move to the beginning and end of the current defun
  523. are `C-M-a' (`beginning-of-defun') and `C-M-e' (`end-of-defun').
  524.    If you wish to operate on the current defun, use `C-M-h'
  525. (`mark-defun') which puts point at the beginning and mark at the end of
  526. the current or next defun.  For example, this is the easiest way to get
  527. ready to move the defun to a different place in the text.  In C mode,
  528. `C-M-h' runs the function `mark-c-function', which is almost the same
  529. as `mark-defun'; the difference is that it backs up over the argument
  530. declarations, function name and returned data type so that the entire C
  531. function is inside the region.  *Note Marking Objects::.
  532.    Emacs assumes that any open-parenthesis found in the leftmost column
  533. is the start of a defun.  Therefore, *never put an open-parenthesis at
  534. the left margin in a Lisp file unless it is the start of a top level
  535. list.  Never put an open-brace or other opening delimiter at the
  536. beginning of a line of C code unless it starts the body of a function.*
  537. The most likely problem case is when you want an opening delimiter at
  538. the start of a line inside a string.  To avoid trouble, put an escape
  539. character (`\', in C and Emacs Lisp, `/' in some other Lisp dialects)
  540. before the opening delimiter.  It will not affect the contents of the
  541. string.
  542.    In the remotest past, the original Emacs found defuns by moving
  543. upward a level of parentheses until there were no more levels to go up.
  544. This always required scanning all the way back to the beginning of the
  545. buffer, even for a small function.  To speed up the operation, Emacs
  546. was changed to assume that any `(' (or other character assigned the
  547. syntactic class of opening-delimiter) at the left margin is the start
  548. of a defun.  This heuristic is nearly always right and avoids the
  549. costly scan; however, it mandates the convention described above.
  550. File: emacs,  Node: Program Indent,  Next: Matching,  Prev: Defuns,  Up: Programs
  551. Indentation for Programs
  552. ========================
  553.    The best way to keep a program properly indented is to use Emacs to
  554. re-indent it as you change it.  Emacs has commands to indent properly
  555. either a single line, a specified number of lines, or all of the lines
  556. inside a single parenthetical grouping.
  557. * Menu:
  558. * Basic Indent::    Indenting a single line.
  559. * Multi-line Indent::   Commands to reindent many lines at once.
  560. * Lisp Indent::        Specifying how each Lisp function should be indented.
  561. * C Indent::        Choosing an indentation style for C code.
  562. File: emacs,  Node: Basic Indent,  Next: Multi-line Indent,  Up: Program Indent
  563. Basic Program Indentation Commands
  564. ----------------------------------
  565. `TAB'
  566.      Adjust indentation of current line.
  567. `LFD'
  568.      Equivalent to RET followed by TAB (`newline-and-indent').
  569.    The basic indentation command is TAB, which gives the current line
  570. the correct indentation as determined from the previous lines.  The
  571. function that TAB runs depends on the major mode; it is
  572. `lisp-indent-line' in Lisp mode, `c-indent-line' in C mode, etc.  These
  573. functions understand different syntaxes for different languages, but
  574. they all do about the same thing.  TAB in any programming language
  575. major mode inserts or deletes whitespace at the beginning of the
  576. current line, independent of where point is in the line.  If point is
  577. inside the whitespace at the beginning of the line, TAB leaves it at
  578. the end of that whitespace; otherwise, TAB leaves point fixed with
  579. respect to the characters around it.
  580.    Use `C-q TAB' to insert a tab at point.
  581.    When entering a large amount of new code, use LFD
  582. (`newline-and-indent'), which is equivalent to a RET followed by a TAB.
  583. LFD creates a blank line, and then gives it the appropriate
  584. indentation.
  585.    TAB indents the second and following lines of the body of a
  586. parenthetical grouping each under the preceding one; therefore, if you
  587. alter one line's indentation to be nonstandard, the lines below will
  588. tend to follow it.  This is the right behavior in cases where the
  589. standard result of TAB is unaesthetic.
  590.    Remember that an open-parenthesis, open-brace or other opening
  591. delimiter at the left margin is assumed by Emacs (including the
  592. indentation routines) to be the start of a function.  Therefore, you
  593. must never have an opening delimiter in column zero that is not the
  594. beginning of a function, not even inside a string.  This restriction is
  595. vital for making the indentation commands fast; you must simply accept
  596. it.  *Note Defuns::, for more information on this.
  597. File: emacs,  Node: Multi-line Indent,  Next: Lisp Indent,  Prev: Basic Indent,  Up: Program Indent
  598. Indenting Several Lines
  599. -----------------------
  600.    When you wish to re-indent several lines of code which have been
  601. altered or moved to a different level in the list structure, you have
  602. several commands available.
  603. `C-M-q'
  604.      Re-indent all the lines within one list (`indent-sexp').
  605. `C-u TAB'
  606.      Shift an entire list rigidly sideways so that its first line is
  607.      properly indented.
  608. `C-M-\'
  609.      Re-indent all lines in the region (`indent-region').
  610.    You can re-indent the contents of a single list by positioning point
  611. before the beginning of it and typing `C-M-q' (`indent-sexp' in Lisp
  612. mode, `indent-c-exp' in C mode; also bound to other suitable commands
  613. in other modes).  The indentation of the line the sexp starts on is not
  614. changed; therefore, only the relative indentation within the list, and
  615. not its position, is changed.  To correct the position as well, type a
  616. TAB before the `C-M-q'.
  617.    If the relative indentation within a list is correct but the
  618. indentation of its beginning is not, go to the line the list begins on
  619. and type `C-u TAB'.  When TAB is given a numeric argument, it moves all
  620. the lines in the grouping starting on the current line sideways the
  621. same amount that the current line moves.  It is clever, though, and
  622. does not move lines that start inside strings, or C preprocessor lines
  623. when in C mode.
  624.    Another way to specify the range to be re-indented is with point and
  625. mark.  The command `C-M-\' (`indent-region') applies TAB to every line
  626. whose first character is between point and mark.
  627. File: emacs,  Node: Lisp Indent,  Next: C Indent,  Prev: Multi-line Indent,  Up: Program Indent
  628. Customizing Lisp Indentation
  629. ----------------------------
  630.    The indentation pattern for a Lisp expression can depend on the
  631. function called by the expression.  For each Lisp function, you can
  632. choose among several predefined patterns of indentation, or define an
  633. arbitrary one with a Lisp program.
  634.    The standard pattern of indentation is as follows: the second line
  635. of the expression is indented under the first argument, if that is on
  636. the same line as the beginning of the expression; otherwise, the second
  637. line is indented underneath the function name.  Each following line is
  638. indented under the previous line whose nesting depth is the same.
  639.    If the variable `lisp-indent-offset' is non-`nil', it overrides the
  640. usual indentation pattern for the second line of an expression, so that
  641. such lines are always indented `lisp-indent-offset' more columns than
  642. the containing list.
  643.    The standard pattern is overridden for certain functions.  Functions
  644. whose names start with `def' always indent the second line by
  645. `lisp-body-indent' extra columns beyond the open-parenthesis starting
  646. the expression.
  647.    The standard pattern can be overridden in various ways for individual
  648. functions, according to the `lisp-indent-hook' property of the function
  649. name.  There are four possibilities for this property:
  650. `nil'
  651.      This is the same as no property; the standard indentation pattern
  652.      is used.
  653. `defun'
  654.      The pattern used for function names that start with `def' is used
  655.      for this function also.
  656. a number, NUMBER
  657.      The first NUMBER arguments of the function are "distinguished"
  658.      arguments; the rest are considered the "body" of the expression.
  659.      A line in the expression is indented according to whether the
  660.      first argument on it is distinguished or not.  If the argument is
  661.      part of the body, the line is indented `lisp-body-indent' more
  662.      columns than the open-parenthesis starting the containing
  663.      expression.  If the argument is distinguished and is either the
  664.      first or second argument, it is indented *twice* that many extra
  665.      columns.  If the argument is distinguished and not the first or
  666.      second argument, the standard pattern is followed for that line.
  667. a symbol, SYMBOL
  668.      SYMBOL should be a function name; that function is called to
  669.      calculate the indentation of a line within this expression.  The
  670.      function receives two arguments:
  671.     STATE
  672.           The value returned by `parse-partial-sexp' (a Lisp primitive
  673.           for indentation and nesting computation) when it parses up to
  674.           the beginning of this line.
  675.     POS
  676.           The position at which the line being indented begins.
  677.      It should return either a number, which is the number of columns of
  678.      indentation for that line, or a list whose car is such a number.
  679.      The difference between returning a number and returning a list is
  680.      that a number says that all following lines at the same nesting
  681.      level should be indented just like this one; a list says that
  682.      following lines might call for different indentations.  This makes
  683.      a difference when the indentation is being computed by `C-M-q'; if
  684.      the value is a number, `C-M-q' need not recalculate indentation
  685.      for the following lines until the end of the list.
  686. File: emacs,  Node: C Indent,  Prev: Lisp Indent,  Up: Program Indent
  687. Customizing C Indentation
  688. -------------------------
  689.    Two variables control which commands perform C indentation and when.
  690.    If `c-auto-newline' is non-`nil', newlines are inserted both before
  691. and after braces that you insert, and after colons and semicolons.
  692. Correct C indentation is done on all the lines that are made this way.
  693.    If `c-tab-always-indent' is `nil', the TAB command in C mode does
  694. indentation only if point is at the left margin or within the line's
  695. indentation.  If there is non-whitespace to the left of point, then TAB
  696. just inserts a tab character in the buffer.  Normally, this variable is
  697. `t', and TAB always reindents the current line.  The default behavior
  698. means that to insert a real tab character you must quote it by typing
  699. `C-q' TAB.
  700.    C does not have anything analogous to particular function names for
  701. which special forms of indentation are desirable.  However, it has a
  702. different need for customization facilities: many different styles of C
  703. indentation are in common use.
  704.    There are six variables you can set to control the style that Emacs C
  705. mode uses.
  706. `c-indent-level'
  707.      Indentation of C statements within surrounding block.  The
  708.      surrounding block's indentation is the indentation of the line on
  709.      which the open-brace appears.
  710. `c-continued-statement-offset'
  711.      Extra indentation given to a substatement, such as the then-clause
  712.      of an if or body of a while.
  713. `c-brace-offset'
  714.      Extra indentation for line if it starts with an open brace.
  715. `c-brace-imaginary-offset'
  716.      An open brace following other text is treated as if it were this
  717.      far to the right of the start of its line.
  718. `c-argdecl-indent'
  719.      Indentation level of declarations of C function arguments.
  720. `c-label-offset'
  721.      Extra indentation for line that is a label, or case or default.
  722.    The variable `c-indent-level' controls the indentation for C
  723. statements with respect to the surrounding block.  In the example
  724.          {
  725.            foo ();
  726. the difference in indentation between the lines is `c-indent-level'.
  727. Its standard value is 2.
  728.    If the open-brace beginning the compound statement is not at the
  729. beginning of its line, the `c-indent-level' is added to the indentation
  730. of the line, not the column of the open-brace.  For example,
  731.      if (losing) {
  732.        do_this ();
  733. One popular indentation style is that which results from setting
  734. `c-indent-level' to 8 and putting open-braces at the end of a line in
  735. this way.  I prefer to put the open-brace on a separate line.
  736.    In fact, the value of the variable `c-brace-imaginary-offset' is
  737. also added to the indentation of such a statement.  Normally this
  738. variable is zero.  Think of this variable as the imaginary position of
  739. the open brace, relative to the first nonblank character on the line.
  740. By setting this variable to 4 and `c-indent-level' to 0, you can get
  741. this style:
  742.      if (x == y) {
  743.          do_it ();
  744.          }
  745.    When `c-indent-level' is zero, the statements inside most braces
  746. will line up right under the open brace.  But there is an exception made
  747. for braces in column zero, such as surrounding a function's body.  The
  748. statements just inside it do not go at column zero.  Instead,
  749. `c-brace-offset' and `c-continued-statement-offset' (see below) are
  750. added to produce a typical offset between brace levels, and the
  751. statements are indented that far.
  752.    `c-continued-statement-offset' controls the extra indentation for a
  753. line that starts within a statement (but not within parentheses or
  754. brackets).  These lines are usually statements that are within other
  755. statements, such as the then-clauses of `if' statements and the bodies
  756. of `while' statements.  This parameter is the difference in indentation
  757. between the two lines in
  758.      if (x == y)
  759.        do_it ();
  760. Its standard value is 2.  Some popular indentation styles correspond to
  761. a value of zero for `c-continued-statement-offset'.
  762.    `c-brace-offset' is the extra indentation given to a line that
  763. starts with an open-brace.  Its standard value is zero; compare
  764.      if (x == y)
  765.        {
  766.      if (x == y)
  767.        do_it ();
  768. if `c-brace-offset' were set to 4, the first example would become
  769.      if (x == y)
  770.            {
  771.    `c-argdecl-indent' controls the indentation of declarations of the
  772. arguments of a C function.  It is absolute: argument declarations
  773. receive exactly `c-argdecl-indent' spaces.  The standard value is 5,
  774. resulting in code like this:
  775.      char *
  776.      index (string, c)
  777.           char *string;
  778.           int c;
  779.    `c-label-offset' is the extra indentation given to a line that
  780. contains a label, a case statement, or a `default:' statement.  Its
  781. standard value is -2, resulting in code like this
  782.      switch (c)
  783.        {
  784.        case 'x':
  785. If `c-label-offset' were zero, the same code would be indented as
  786.      switch (c)
  787.        {
  788.          case 'x':
  789. This example assumes that the other variables above also have their
  790. standard values.
  791.    I strongly recommend that you try out the indentation style produced
  792. by the standard settings of these variables, together with putting open
  793. braces on separate lines.  You can see how it looks in all the C source
  794. files of GNU Emacs.
  795. File: emacs,  Node: Matching,  Next: Comments,  Prev: Program Indent,  Up: Programs
  796. Automatic Display Of Matching Parentheses
  797. =========================================
  798.    The Emacs parenthesis-matching feature is designed to show
  799. automatically how parentheses match in the text.  Whenever you type a
  800. self-inserting character that is a closing delimiter, the cursor moves
  801. momentarily to the location of the matching opening delimiter, provided
  802. that is on the screen.  If it is not on the screen, some text near it is
  803. displayed in the echo area.  Either way, you can tell what grouping is
  804. being closed off.
  805.    In Lisp, automatic matching applies only to parentheses.  In C, it
  806. applies to braces and brackets too.  Emacs knows which characters to
  807. regard as matching delimiters based on the syntax table, which is set
  808. by the major mode.  *Note Syntax::.
  809.    If the opening delimiter and closing delimiter are mismatched--such
  810. as in `[x)'--a warning message is displayed in the echo area.  The
  811. correct matches are specified in the syntax table.
  812.    Two variables control parenthesis match display.
  813. `blink-matching-paren' turns the feature on or off; `nil' turns it off,
  814. but the default is `t' to turn match display on.
  815. `blink-matching-paren-distance' specifies how many characters back to
  816. search to find the matching opening delimiter.  If the match is not
  817. found in that far, scanning stops, and nothing is displayed.  This is
  818. to prevent scanning for the matching delimiter from wasting lots of
  819. time when there is no match.  The default is 12,000.
  820.